﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using RED_NET_Core.Helper;
namespace RED_NET_Core.Entity
{
    public class Users
    {
        #region [Message Of User]

        private int _userId;
        private string _userName;
        private string _password;
        private DateTime _lastLoginTime;
        private bool _status;
        private int _college;
        private int _major;
        private int _class;
        private int _right;
        private int _myAttention;
        private int _attentionBy;
        private int _blogNum;
        private string _nickName;
        private int[] _visitorId = new int[5];
        private int _top;///最新访客用数组模拟队列实现，top为最新访客所在数组地址。
        private string _avatarUrl;
        #endregion

        #region [Properties Of User]
        public string AvatarUrl
        {
            get { return _avatarUrl; }
            set { _avatarUrl = value; }
        }
        public int UserId
        {
            get { return _userId; }
            set { _userId = value; }
        }

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public DateTime LastLoginTime
        {
            get { return _lastLoginTime; }
            set { _lastLoginTime = value; }
        }

        public bool Status
        {
            get { return _status; }
            set { _status = value; }
        }
        public int College
        {
            get { return _college; }
            set { _college = value; }
        }
        public int Major
        {
            get { return _major; }
            set { _major = value; }
        }
        public int Class
        {
            get { return _class; }
            set { _class = value; }
        }
        public int Right
        {
            get { return _right; }
            set { _right = value; }
        }
        public int Myattention
        {
            get { return _myAttention; }
            set { _myAttention = value; }
        }
        public int AttentionBy
        {
            get { return _attentionBy; }
            set { _attentionBy = value; }
        }
        public int BlogNum
        {
            get { return _blogNum; }
            set { _blogNum = value; }
        }
        public string NickName
        {
            get { return _nickName; }
            set { _nickName = value; }
        }

        public int Top
        {
            get { return _top; }
            set { _top = value; }
        }

        public int VisitorOne
        {
            get { return _visitorId[0]; }
            set { _visitorId[0] = value; }
        }

        public int VisitorTwo
        {
            get { return _visitorId[1]; }
            set { _visitorId[1] = value; }
        }

        public int VisitorThree
        {
            get { return _visitorId[2]; }
            set { _visitorId[2] = value; }
        }

        public int VisitorFour
        {
            get { return _visitorId[3]; }
            set { _visitorId[3] = value; }
        }

        public int VisitorFive
        {
            get { return _visitorId[4]; }
            set { _visitorId[4] = value; }
        }

        #endregion

        #region [Construct Of User]

        /// <summary>
        /// 空构造函数
        /// </summary>
        public Users() { }

        public Users(int nuserId, string nuserName, string npassword, DateTime nlastLoginTime,
            bool nstatus, int ncollege, int nmajor,int nclass, int nright, int nmyAttention,
            int nattentionBy, int nblogNum, string nnickName, int nvisitorIdOne, int nvisitorIdTwo,
            int nvisitorIdThree, int nvisitorIdFour, int nvisitorIdFive, int ntop)
        {
            _userId = nuserId;
            _userName = nuserName;
            _password = npassword;
            _lastLoginTime = nlastLoginTime;
            _status = nstatus;
            _college = ncollege;
            _major = nmajor;
            _class = nclass;
            _right = nright;
            _myAttention = nmyAttention;
            _attentionBy = nattentionBy;
            _blogNum = nblogNum;
            _nickName = nnickName;
            _visitorId[0] = nvisitorIdOne;
            _visitorId[1] = nvisitorIdTwo;
            _visitorId[2] = nvisitorIdThree;
            _visitorId[3] = nvisitorIdFour;
            _visitorId[4] = nvisitorIdFive;
            _top = ntop;
        }

        #endregion

        #region [AddItem]
        /// <summary>
        /// 在数据库中添加一条记录
        /// </summary>
        /// <returns></returns>
        public int AddItem()
        {
            int _id = -1;
            SqlParameter[] _param = new SqlParameter[18];
            _param[0] = new SqlParameter("@Visit5", _visitorId[4].ToString());
            _param[1] = new SqlParameter("@UserName", _userName.ToString());
            _param[2] = new SqlParameter("@Password", _password.ToString());
            _param[3] = new SqlParameter("@LaseLoginTime", _lastLoginTime.ToString());
            _param[4] = new SqlParameter("@Status", _status.ToString());
            _param[5] = new SqlParameter("@College", College.ToString());
            _param[6] = new SqlParameter("@Major", _major.ToString());
            _param[7] = new SqlParameter("@Class", _class.ToString());
            _param[8] = new SqlParameter("@Right", _right.ToString());
            _param[9] = new SqlParameter("@MyAttention", _myAttention.ToString());
            _param[10] = new SqlParameter("@AttentionBy", _attentionBy.ToString());
            _param[11] = new SqlParameter("@BlogNum", _blogNum.ToString());
            _param[12] = new SqlParameter("@NickName", _nickName.ToString());
            _param[13] = new SqlParameter("@Visit1", _visitorId[0].ToString());
            _param[14] = new SqlParameter("@Visit2", _visitorId[1].ToString());
            _param[15] = new SqlParameter("@Visit3", _visitorId[2].ToString());
            _param[16] = new SqlParameter("@Visit4", _visitorId[3].ToString());
            _param[16] = new SqlParameter("@AvatarUrl", _avatarUrl.ToString());

            string _smdStr = "insert into _Users(_UserName,_Password,_LaseLoginTime,_Status,_College,_Major,_Class,_Right,_MyAttention,_AttentionBy,_BlogNum,_NickName,_Visit1,_Visit2,_Visit3,_Visit4,_Visit5,_AvatarUrl) values(@UserName,@Password,@LaseLoginTime,@Status,@College,@Major,@Class,@Right,@MyAttention,@AttentionBy,@BlogNum,@NickName,@Visit1,@Visit2,@Visit3,@Visit4,@Visit5,@AvatarUrl) SELECT   SCOPE_IDENTITY()   as   '_Id'";
            OwnSqlHelper _shp = new OwnSqlHelper();
            try
            {
                _id = Int32.Parse(_shp.ExecuteScalar(_smdStr, _param));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return _id;
        }
        #endregion
    }
}
